package com.lcz.cloud_note.util;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class ActionUtils
{
    private static Map<String, Date> upMap = new HashMap();
    private static Map<String, Date> downMap = new HashMap();


    /**
     * 这里只是简单的写,如果真的要生产,需要持久化和每天定时清空已过期的值
     */
    public static boolean upAction(String userId,String actionDetailId)
    {
        String str = userId+":"+actionDetailId;
        Date date = upMap.get(str);
        if(date == null)
        {
            upMap.put(str,new Date());
            return true;
        }else
            {
                if(date.getTime()-new Date().getTime()>=86399999)
                {
                    upMap.put(str,new Date());
                    return true;
                }
                return false;
            }
    }
    public static boolean downAction(String userId,String actionDetailId)
    {
        String str = userId+":"+actionDetailId;
        Date date = downMap.get(str);
        if(date == null)
        {
            downMap.put(str,new Date());
            return true;
        }else
        {
            if(date.getTime()-new Date().getTime()>=86399999)
            {
                downMap.put(str,new Date());
                return true;
            }
            return false;
        }
    }
}
